/**
 * 发票管理
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
    console.log('------$scope.menuId1-----', $scope.menuId);
    console.log('------$scope.buttonArr1-----', $scope.buttonArr);

    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        switch(event){

            case 'event-to-cancel': {//登记取消
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else if(datas.length > 1) {
                    layer.alert('只能选中一行数据');
                } else {
                    var customsNum = datas[0].customsNum;
                    if(customsNum != 0 ){
                        return layer.msg("存在报关数量不允许取消");
                    }
                    layer.confirm('确定要取消吗？', { icon: 3 }, function() {
                        layer.msg('处理中', { icon: 16, shade: 0.01 });
                        $http.post('/api/inter/tcgInvoiceOffsetByManage/cancelInfo', {}, {params: {id: datas[0].id}})
                            .success(function (res) {
                                if (res.code == 0) {
                                    layer.msg(res.msg);
                                    setTimeout(function(){
                                        layer.closeAll();
                                        location.reload();
                                    }, 3000);
                                } else {
                                    layer.msg(res.msg);
                                    layer.closeAll();
                                }
                            })
                            .error(function(result){
                                layer.close();
                                layer.msg("操作失败，请稍后再试！", {icon: 2});
                            });

                    }, function() {
                    });
                }
                break;
            }
            case 'event-to-export': {
                $scope.doExport('/api/inter/tcgInvoiceOffsetByManage/export');
                break;
            }

        };
    }
}

//表格双击
app.controller('dbClickCtrl', ['$scope', '$http', DbClickController]);
function DbClickController($scope, $http){
    $scope.doubleClick = function(data) {
        window.top.add_tab('发票管理 - 详情','/web/purchase/tcgInvoiceOffsetByManage/toDetail?bid=' + data.bid);
    }
}


